import React from 'react';
import { observer, inject } from 'mobx-react';
import * as asyncLoad from '../util/asyncLoad';
import { workflowPublicFiles } from '../constants/fileConfig';
import {getAntd,getEcCom,getLabel } from '../util/convert';
import {doSupervise} from '../apis/req';
import {DO_SUPERVISE} from '../constants/type';
import {reloadListPage} from '../util/formUtil';
import * as SignUtil from '../util/signUtil';

@inject('globalStore', 'layoutStore')
@observer
export default class BatchSubmit extends React.Component{
    constructor(){
        super();
        this.state = {hasLoad: false};
    }
    componentDidMount(){
        const init = () =>{
            this.setState({hasLoad: true});
        }
        asyncLoad.asyncLoadModule('workflowPublic', workflowPublicFiles, init);
    }
    render(){
        const { hasLoad ,store} = this.state;
        if(hasLoad){
            const { WfBatchSubmit} = window.weaWorkflowPublic;
            const { globalStore,visible } = this.props;
            const {rightMenu = {}} = globalStore;
            const {rightMenuNames = {}} = rightMenu;
            const onSubmitText = rightMenuNames['SUPERVISE_0'] || getLabel(21223,'督办');
            return (<WfBatchSubmit ecId={`${this && this.props && this.props.ecId || ''}_WfBatchSubmit@d41okx`} onSubmit={this.doSupervise} onCancel={this.onCancel} visible={visible} onSubmitText={onSubmitText} iconClassName={'icon-coms-daiban'}/>);
        }else{
            return ( <div></div>);
        }
    }

    //督办
    doSupervise = (remark = '') => {
        const {message} = getAntd();
        const { globalStore } = this.props;
        const { baseParam,batchControlVariableMap,markInfo = {} } = globalStore;
        const {isSignMustInput} = markInfo;
        const { requestid,f_weaver_belongto_userid } = baseParam;  
        let tempRequestid = requestid.toString() + "_" + f_weaver_belongto_userid.toString();
        let flag = true;
        if(isSignMustInput == '1' || (isSignMustInput == '2' && SignUtil.verifyRemarkMustInput('supervise'))) {
            flag = SignUtil.chekcremark(remark);
        }
        if(flag) {
            let params = {requestids:tempRequestid,remark};
            message.loading(getLabel(387110,'督办中...，请稍候'),0);
            doSupervise(params).then((data)=>{
                message.destroy();
                if(data.result){
                    message.success(getLabel(387108,'督办成功'));
                    this.onCancel();

                    //刷新签字意见列表
                    const reloadLogListParams = {pgnumber: 1,atmet: '',maxrequestlogid: 0};
                    batchControlVariableMap({'isRelaodLogList':true,'reloadLogListParams':reloadLogListParams});
                    //刷新督办列表
                    reloadListPage();
                }else{
                    message.error(getLabel(387109,'督办失败'));
                }
            })
        } else {
            const { message } = getAntd();
            message.warning(getLabel(386186,'"签字意见"未填写'),2);
        }
    }

    //关闭
    onCancel = () => {
        this.props.globalStore.controlDialogVisible(DO_SUPERVISE, false);
    }
}